#include "UdpClient.hpp"
#include <signal.h>
using namespace UdpClientModule;

std::unique_ptr<UdpClient> client;
void quit(int sig)
{
    std::cout<<"ctrc + c "<<std::endl;
    const std::string quit = "QUIT";
    int n = ::sendto(client->fd(), quit.c_str(), quit.size(), 0,client->Inetaddress(), sizeof(client->Inetaddress()));
    exit(0);
}
int main(int argc, char *argv[])
{

    if (argc != 3) // 客户端必须传入我们要发送的目的地的IP和端口号
    {
        std::cout << "Usage: ./client ip port" << std::endl;
        return 1;
    }
    std::string ip = argv[1];
    uint16_t port = std::stoi(argv[2]);
    client = std::make_unique<UdpClient>(ip, port);
    client->InitClient();
    client->SetQuitCb(quit);
    client->Start();

    return 0;
}